<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
  <title>后台管理系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="/resources/css/dpl-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/bui-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/page-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/js/boxy/boxy.css" type="text/css"   rel="stylesheet" />
</head>
<body>

<div class="container">
  <form id="J_Form" class="form-horizontal" action="/user/save">

    <h3>用户信息</h3>
    <input type="hidden" name="id" id="id" value="${data.id}"/>
    <div class="row">
      <div class="control-group span12">
        <label class="control-label">用户微信号：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <input name="weixinName" id="weixinName" type="text" data-rules="{maxlength:50}" value="${data.nickName}" class="input-normal control-text">
          <input type="button" value="请选择" onclick="openSelector1()"/>
          <input name="openId" type="hidden" id="openId" value="${data.openId}" class="input-normal control-text">
        </div>
      </div>

      <div class="control-group span12">
        <label class="control-label">账号：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <input name="account" type="text" data-rules="{required:true,maxlength:20}" value="${account}" class="input-normal control-text">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="control-group span12">
        <label class="control-label">名称：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <input name="nickName" id="nickName" type="text" data-rules="{required:true,maxlength:50}" value="${data.nickName}" class="input-normal control-text">
        </div>
      </div>

      <div class="control-group span12">
        <label class="control-label">手机号码：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <input name="mobile" id="mobile" type="text" data-rules="{required:true,maxlength:20}" value="${data.mobile}" class="input-normal control-text">
        </div>
      </div>
    </div>
    <div class="row">
      <div class="control-group span12">
        <label class="control-label">推荐人账号：</label>
        <div style="display:inline;height:40px;margin-left: 10px;">
          <input name="recommendName" id="recommendName" type="text" data-rules="{maxlength:20}" value="${upper}"
                 class="input-normal control-text">
          <input type="button" value="查询" onclick="queryUser()"/>
          <input type="hidden" id="recommendId" name="recommendId" value="${data.recommendId}"/>
        </div>
      </div>
    </div>
    <input type="hidden" name="status" id="status" value="NORMAL"/>
      <div  id="user_list" style="display: none;margin-top: 10px;">
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;推荐人:
        <span id="span_list">

        </span>
      </div>


    <div class="row form-actions actions-bar">
      <div class="span13 offset3 ">
        <button type="submit" class="button button-primary">保存</button>
        <button type="button" class="button" onclick="back()">返回</button>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript" src="/resources/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/resources/js/bui-min.js"></script>
<script type="text/javascript" src="/resources/js/config-min.js"></script>
<script type="text/javascript" src="/resources/js/boxy/jquery.boxy.js" ></script>

<script type="text/javascript">
  BUI.use('common/page'); //页面链接跳转
  BUI.use(['bui/tree','bui/form','bui/select','bui/data'],function (Tree,Form,Select,Data) {
    var form = new Form.HForm({
      srcNode : '#J_Form',
      submitType:"ajax",
      listeners:{
        beforesubmit:function(){
          var recommendId = $("#recommendId").val();
          if(recommendId==""){
            if(confirm("确定不为该用户分配推荐人？")){
              return true;
            }else{
              return false;
            }
            /*BUI.Message.Confirm("确定不为该用户分配推荐人？",function(){
                return true;
            },'question');*/
          }else{
            return true;
          }
        }
      },
      callback:function(data){
        BUI.Message.Alert(data.msg,function(){
          if(data.success){
            back();
          }
        },'info');
      }
    });

    form.render();
  });

  function back(){
    var type = '${data.type}';
    if(type=='Customer') {
      top.topManager.openPage({
        id: 'weixin_user',
        isClose: true
      });
      top.topManager.reloadPage('weixin_user');
    }else{
      top.topManager.openPage({
        id: 'user_list',
        isClose: true
      });
      top.topManager.reloadPage('user_list');
    }
  }

  function openSelector1(){
      new Boxy(
              "<iframe style='width:400px;height:400px;'  id='Iframe_Edit' src='/front/listSelector1?Rnd=" + Math.random()+"' frameborder='no' border='0' marginwidth='0' marginheight='0' scrolling='no' allowtransparency='yes'></iframe>", {
                  title:"选择推荐人",
                  modal:true,
                  behaviours: function(c) {
                  },
                  afterHide: function() {
                  }
              }
      );
  }

  function selectOK1(id,name){
      $("#openId").val(id);
      $("#nickName").val(name);
      $("#weixinName").val(name);
      return true;
  }

  function openSelector(){
    new Boxy(
            "<iframe style='width:400px;height:450px;'  id='Iframe_Edit' src='/front/listSelector?Rnd=" + Math.random()+"' frameborder='no' border='0' marginwidth='0' marginheight='0' scrolling='no' allowtransparency='yes'></iframe>", {
              title:"选择推荐人",
              modal:true,
              behaviours: function(c) {
              },
              afterHide: function() {
              }
            }
    );
  }

  function selectOK(id,name){
    $("#recommendId").val(id);
    $("#recommendName").val(name);
    return true;
  }

  function queryUser(){
    var recommendName = $("#recommendName").val();
    if(recommendName!=''){
      $("#user_list").show();
        $.ajax({
          url:"/front/listUser",
          type:"post",
          data:{
            name:recommendName
          },
          success:function(res){
            if(res.success){
              var html = "";
              $.each(res.data,function(i,n){
                var chk = "";
                  html += "&nbsp;&nbsp;<input type='radio' name='user' value='"+n.id+"_"+n.account+"' id='id_"+n.id+"' " +
                          "onclick=\"selectData('"+n.id+"')\" /><img src='"+n.headImgUrl+"' style='width:80px;height:80px;'/>"+n.account;
              });
              $("#span_list").html(html);
            }
          },
          error:function(){}
        })
    }else{
      $("#user_list").hide();
    }
  }

  function selectData(id){
    var obj = $("#id_"+id);
    if(obj!=undefined){
      var val = obj.val();
      if(val!=''){
        var id = val.split("_")[0];
        var account = val.split("_")[1];
        $("#recommendId").val(id);
        $("#recommendName").val(account);
      }
    }
  }

</script>

</body>
</html> 